﻿package sedie 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import game.events.EventData;
	import game.SoundList;
	/**
	 * ...
	 * @author ... Doan Nguyen Thuy Nha Truc (Bamboo)	
	 */
	public class SoundList extends MovieClip
	{
		public var musicList:game.SoundList;
		public var icon:MovieClip;
		public function SoundList() 
		{
			this.addEventListener(MouseEvent.ROLL_OUT, rollOutHdl);
			this.icon.addEventListener(MouseEvent.ROLL_OVER, rollOverHdl);
			this.icon.addEventListener(MouseEvent.CLICK, iconHdl);
			this.addEventListener(EventData.UPDATE_SOUNDBACKGROUND, hdlUpdateSoundBackground);
			this.hide();
		}
		
		private function hdlUpdateSoundBackground(e:EventData):void 
		{
			if(this.icon.currentLabel == "stop") {
				this.icon.gotoAndStop("play");
			}
		}
		
		private function iconHdl(e:MouseEvent):void 
		{
			if (this.icon.currentLabel == "play") {
				this.icon.gotoAndStop("stop");
				this.hide();
				dispatchEvent(new EventData(EventData.STOP_LIST_SOUND, true));
			} else {
				this.icon.gotoAndStop("play");				
				//call play sound	
				dispatchEvent(new EventData(EventData.UPDATE_SOUNDBACKGROUND, true));
				
			}
		}
		
		public function stopSound():void {
			if (this.icon.currentLabel == "play") {
				
				this.icon.gotoAndStop("stop");
				this.hide();
				trace("stopSound11111111");
			}
		}
		private function rollOutHdl(e:MouseEvent):void 
		{
			this.hide();
		}
		
		private function rollOverHdl(e:MouseEvent):void 
		{
			this.show();
		}
		
		public function hide():void {
			if(this.musicList.visible)
			{	
				this.musicList.visible = false;
				trace("hide musicList");}
		}
		public function show():void {
			if(!this.musicList.visible)
			{	
				this.musicList.visible =  true;
				trace("show musicList");}
		}
	}

}